// pages/user/faq.js
const config = require('../../config')
const util = require('../../utils/util')
var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        showindex: 0,
        faq:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getfaqinfo()
    },
    //保存formid
    saveform: function (e) {
        var formid = e.detail.formId
        app.saveformid(formid)
    },
    getfaqinfo(){
        var that = this
        if (app.globalData.uid) {
            var headerkey = util.createheaderkey()
            wx.request({
                url: config.host + '/api/faq/faqInfo',
                method: 'GET',
                header: {
                    'content-type': 'application/json',
                    'key': headerkey.key,
                    'time': headerkey.timestamp
                },
                data: {
                    uid: app.globalData.uid
                },
                success: function (res) {
                    if (res.data.code == 200) {
                        that.setData({
                            faq: res.data.data
                        })
                    } else {
                        wx.showModal({
                            title: '失败',
                            content: res.data.msg,
                            showCancel: false
                        })
                    }
                },
                fail: function (res) {
                    wx.showToast({
                        title: '常见问题获取失败!',
                        duration: 3000
                    })
                }
            })
        } else {
            setTimeout(function () {
                that.getfaqinfo()
            }, 1000)
        }
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
    
    },
    showfaq:function (e) {
        this.setData({
            showindex: e.currentTarget.dataset.index
        })
    }
})